﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GuitarShop.Models
{
    public class ShopModels
    {
        GuitarShopEntities aGuitarShopEntities = new GuitarShopEntities();
        public List<Slider> GetSliderShop()
        {
            return aGuitarShopEntities.Sliders.Where(x => x.SliderType == 2).ToList();
        }

        public List<Product> GetProductsShopIndex(int idShop)
        {            
            var aListProduct = new List<Product>();
            if (idShop == 1)
            {
                var aListGuitarClassic =
                aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                    .Where(x => x.ProductType == 1);
                aListProduct.AddRange(aListGuitarClassic);
            }
            if (idShop==2)
            {
                var aListGuitarAucostic = aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                        .Where(x => x.ProductType == 2);
                aListProduct.AddRange(aListGuitarAucostic);
            }
            if (idShop==3)
            {
                var aListGuitarPhuKien = aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                        .Where(x => x.ProductType == 3);
                aListProduct.AddRange(aListGuitarPhuKien);
            }
            if (idShop==0)
            {
                var aListGuitarClassic =
                aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                    .Where(x => x.ProductType == 1)
                    .Take(3);
                var aListGuitarAucostic = aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                        .Where(x => x.ProductType == 2)
                        .Take(3);
                var aListGuitarPhuKien = aGuitarShopEntities.Products.OrderByDescending(s => s.ProductId)
                        .Where(x => x.ProductType == 3)
                        .Take(3);
                aListProduct.AddRange(aListGuitarClassic);
                aListProduct.AddRange(aListGuitarAucostic);
                aListProduct.AddRange(aListGuitarPhuKien);
            }
            
            return aListProduct;
        }

        public Product GetDetailProduct(int pProductId)
        {
            return aGuitarShopEntities.Products.Where(x => x.ProductId == pProductId).FirstOrDefault();
        }
    }
}